package com.simulate2.demo.service;

import com.simulate2.demo.entity.Commision;
import com.simulate2.demo.entity.Date_commision;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Update;
import org.springframework.stereotype.Service;
import org.springframework.data.mongodb.core.query.Query;

import java.math.BigDecimal;

@Service
public class MongoDbService {
    @Autowired
    private MongoTemplate mongoTemplate;

    public void myUpsert(Integer uId, Integer date, BigDecimal uCommision){
        Query query = new Query(Criteria.where("uId").is(uId));
        query.addCriteria(Criteria.where("_class").is("com.simulate2.demo.entity.Commision"));
        Update update=new Update();
        Date_commision d=new Date_commision(date,uCommision);
        update.addToSet("date_commisionList",d);
        mongoTemplate.upsert(query,update, Commision.class);

    }
}
